package com.market.member.service.login;

import com.block.common.constant.AppRspCodeConstant;
import com.block.common.model.dto.LoginReqDTO;
import com.block.common.service.IAppLoginInfoService;
import com.block.common.service.IMemberCommonService;
import com.block.common.vo.ResponseVo;
import com.block.db.entity.MemberInfo;
import com.block.db.mapper.MemberInfoMapper;
import com.market.member.model.dto.LoginResultDTO;
import com.market.member.service.ILoginTypeService;
import com.market.member.service.IMemberInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 用户联登
 */
@Slf4j
@Service
public class UnionLoginServiceImpl extends ILoginTypeService {

    @Resource
    MemberInfoMapper memberInfoMapper;
    @Autowired
    IMemberCommonService memberCommonService;

    @Override
    public ResponseVo toLogin(LoginReqDTO loginReqDTO) {

        String uid = loginReqDTO.getMobile();

        MemberInfo memberInfo = memberInfoMapper.getMemberInfoByUidLock(Long.valueOf(uid));
        boolean isNewMember = false;
        if (memberInfo == null){
            return new ResponseVo(AppRspCodeConstant.SYS_EXCEPTION, "用户信息为空","");
        }

        // 登录结果
        LoginResultDTO loginResultDTO = new LoginResultDTO();
        loginResultDTO.setUid(memberInfo.getUid());
        loginResultDTO.setNewMember(isNewMember);
        loginResultDTO.setMemberType(memberInfo.getType());

        return new ResponseVo(AppRspCodeConstant.SUCCESS, loginResultDTO);
    }
}
